﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using Cosmetic.Logic;

namespace WebApp.Management.Product
{
    public partial class FocusProduct : PageBase2
    {
        FocusManager theFocusManager = new FocusManager();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindListView();
            }
        }

        protected void lvProdust_ItemCanceling(object sender, ListViewCancelEventArgs e)
        {
            this.lvProdust.EditIndex = -1;
            BindListView();
        }

        protected void lvProdust_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("OnDelete"))
            {
                theFocusManager.DeleteFocusProduct(int.Parse(e.CommandArgument.ToString()));
                BindListView();
            }
        }

        private void BindListView()
        {
            this.lvProdust.DataSource = theFocusManager.GetFocusProduct();
            this.lvProdust.DataBind();
        }

        protected void lvProdust_ItemEditing(object sender, ListViewEditEventArgs e)
        {
            this.lvProdust.EditIndex = e.NewEditIndex;
            BindListView();
        }

        protected void lvProdust_ItemUpdating(object sender, ListViewUpdateEventArgs e)
        {
            HiddenField hf1 = (this.lvProdust.Items[e.ItemIndex].FindControl("HiddenField1") as HiddenField);
            TextBox txt = this.lvProdust.Items[e.ItemIndex].FindControl("TextBox1") as TextBox;
            theFocusManager.UpdateFocusProductSequence(int.Parse(hf1.Value), int.Parse(txt.Text.Trim()));
            
            this.lvProdust.EditIndex = -1;
            BindListView();
        }

    }
}
